package nhatquang.gs.model;

import nhatquang.gs.controler.ResourcesManager;

import org.andengine.entity.Entity;
import org.andengine.entity.modifier.MoveModifier;
import org.andengine.entity.scene.Scene;
import org.andengine.opengl.texture.region.ITextureRegion;

public class Fruit extends Entity {
	private FruitNomall fruitNomall;
	private FruitSell fruitSell;
	// private

	private Scene scene;
	private int species;

	private int row;
	private int collumn;

	private float endY;

	public Fruit(float x, float y, int row, int collumn,
			ITextureRegion iTextureRegionNormall,
			ITextureRegion iTextureRegionSell, float endY, int species,
			Scene scene) {
		super(x, y);
		fruitNomall = new FruitNomall(0, 0, Public.WIDTH_SPRITE,
				Public.WIDTH_SPRITE, iTextureRegionNormall,
				ResourcesManager.INSTANCE.VBOM, row, collumn, endY, species);
		fruitSell = new FruitSell(0, 0, Public.WIDTH_SPRITE,
				Public.HEIGHT_SPRITE, iTextureRegionSell,
				ResourcesManager.INSTANCE.VBOM, row, collumn);

		this.row = row;
		this.collumn = collumn;

		this.endY = endY;

		this.scene = scene;
		this.species = species;

		scene.registerTouchArea(fruitNomall);
		this.attachChild(fruitNomall);
		
		move();

	}

	public void stateNormall() {
		fruitNomall.setVisible(true);
		this.detachChild(fruitSell);
		this.attachChild(fruitNomall);
	}

	public void stateSell() {
		fruitNomall.setVisible(false);
//		this.detachChild(fruitNomall);
		this.attachChild(fruitSell);
	}

	public int getRow() {
		return row;
	}

	public int getCollumn() {
		return collumn;
	}

	public int getSpecies() {
		return species;
	}

	public FruitNomall getFruitNomall() {
		return fruitNomall;
	}

	public void setRow(int row) {
		this.row = row;
		fruitNomall.setRow(row);
		fruitSell.setRow(row);
	}

	public void setCollumn(int collumn) {
		this.collumn = collumn;
		fruitNomall.setCollumn(collumn);
		fruitSell.setCollumn(collumn);
	}

	public void move() {
		float currentX = this.getX();
		float currentY = this.getY();
		float duration = (endY - currentY) / Public.SPEED_SPRITE;

		MoveModifier move = new MoveModifier(duration, currentX, currentX,
				currentY, endY);

		this.registerEntityModifier(move);
	}
}
